<?php
session_start();
require './lib/ConnectDB.php';
$user = htmlspecialchars(addslashes(trim($_POST['username'])));
$password = htmlspecialchars(addslashes(trim($_POST['password'])));
if(!empty($user)&&!empty($password)){
    $connect = ConnectDB::getInstace();
    $result = $connect->cDb()->query("SELECT * FROM users WHERE username='$user' AND password='$password'");
    if ($result->num_rows==1){
       $user=$result->fetch_assoc();
       $_SESSION['is_login']=1;
       $_SESSION['id_user']=$user['id_user'];
        $_SESSION['name']=$user['username'];
        $_SESSION['rank']=$user['rank'];
        header("Location:dashboard.php");
        exit();
    }
    else{
        $_SESSION['erorr']= "Грешно име или парола";
    }
    
}
 else {
$_SESSION['erorr']= "Попълни и двете полета" ;   
}
header("Location:index.php");